package com.cjr.ddp.controller;

import com.cjr.ddp.entity.DictTarget;
import com.cjr.ddp.service.PageService;
import com.cjr.ddp.service.TarService;
import com.cjr.ddp.util.ReturnMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author cjr
 * @date Created in 2020-03-07 22:04
 * @description 页面控制层
 * @modified By
 */
@RestController
@RequestMapping("/page")
public class PageController {

    @Autowired
    PageService pageService;

    @RequestMapping("/getPageTar")
    public Object getPageTar(String year, String pageid) {
        ReturnMsg returnMsg = new ReturnMsg();
        try {
            List<DictTarget> list = pageService.getPageTar(year, pageid);
            returnMsg.setCode("200");
            returnMsg.setSuccess(true);
            returnMsg.setList(list);
        } catch (Exception ex) {
            returnMsg.setCode("404");
            returnMsg.setSuccess(false);
            returnMsg.setMsg(ex.toString());

        }
        return returnMsg;
    }

    @RequestMapping("/getTrend")
    public Object getTrend(String start, String end, String tarid) {
        ReturnMsg returnMsg = new ReturnMsg();
        try {
            List<Map<Object, Object>> list = pageService.getTrend(start, end, tarid);
            returnMsg.setCode("200");
            returnMsg.setSuccess(true);
            returnMsg.setList(list);
        } catch (Exception ex) {
            returnMsg.setCode("404");
            returnMsg.setSuccess(false);
            returnMsg.setMsg(ex.toString());

        }
        return returnMsg;

    }


}
